package cn.news.control;

import java.io.IOException;
import java.io.PrintWriter;


import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.news.biz.LoginBiz;
import cn.news.entity.User;



public class UserLoginServlet extends HttpServlet {
    
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;Charset=utf-8");
		HttpSession session=request.getSession();
		
		PrintWriter out=response.getWriter();
		LoginBiz lBiz=new LoginBiz();
		
		String name=request.getParameter("uname");
		String pass=request.getParameter("pass");
		User us=lBiz.user(name, pass);

		session.setAttribute("user", us);
		
		String noloading=request.getParameter("noloading");
		//如果一周内保存则判断其条件
		if(noloading!=null || us!=null){
			response.sendRedirect("succ.jsp");
			
		}
		if(us==null){
			out.print("用户名或密码错误，三秒后自动跳转到登录页面请重新登陆或注册新用户");
			response.setHeader("refresh", "3;URL=index.jsp");
		}
	
	}

}
